<?php  
class ControllerCommonFooter extends Controller {
    protected function index(){   
        $this->load->model('tool/seo_url');         
        $this->load->model('tool/image');             
        $this->load->model('catalog/manufacturer');
        $this->load->model('content/category');    
        $this->load->model('content/content');   
                                                        
        $manufacturers = $this->getManufacturers();
        $size = round(count($manufacturers) / 3) ;
        $arr_manufacturers = array_chunk($manufacturers, $size);
       
        
        $this->data['manufacturers'] = $arr_manufacturers;
        
        $this->data['template'] = $this->config->get('config_template');
        $this->data['base_link'] = $this->data['base'] . 'catalog/view/theme/'. $this->config->get('config_template') . '/';
        
        $categories = array();    
        $categories_data = $this->model_content_category->getCategories(0, 1, 4); 
        foreach($categories_data as $category){
            $contents = $this->model_content_content->getContentsByCategoryId($category['category_id'], 'p.sort_order, pd.name', 'ASC', 35, 0);
            
            foreach($contents as &$c_item){
                if($c_item['article_type'] == 'article'){
                    $c_item['href'] = $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=content/item/article&content_id=' . $c_item['content_id']);
                }
                else{
                    if($c_item['url_type'] == 'internal'){
                        $c_item['href'] = $this->model_tool_seo_url->rewrite(HTTP_SERVER . $c_item['url_content']);
                    }
                    else{
                        $c_item['href'] = $c_item['url_content'];    
                    }
                }
            }
            
            $categories[] = array(
                'name'          => $category['name'],
                'children'      => $contents,
            );            
        }               
        $this->data['content_categories'] = $categories;

        $this->language->load('common/footer');
        
        if(stristr($this->config->get('config_email'), 'havhokeren.dk') !== false){
            $email = $this->config->get('config_email');                
        }
        else{
            $email = 'webshop@havhokeren.dk';
        }
        
        $powered_by = '© 2014 Havhøkeren ApS - '; //$this->config->get('config_owner') . ' - ';
        $powered_by .= str_replace("\n", ' - ', $this->config->get('config_address')) . ' - ';
        $powered_by .= 'Tlf. ' . $this->config->get('config_telephone') . ' - ';
        $powered_by .= '<a href="mailto:' . $email . '">' . $email . '</a>';    
		$powered_by .= ' - <b>CVR-nr. 34603278</b>';
        $this->data['text_powered_by'] = $powered_by;
        
        //© 2014 Havhøkeren ApS - Ndr. Havnevej 9 - 3250 Gilleleje - Tlf. 4830 1699 - <a href="mailto:webshop@havhokeren.dk">webshop@havhokeren.dk</a>- CVR-nr. 34603278
        
        $this->data['template'] = $this->config->get('config_template');
		$this->data['search_keywords'] = $this->config->get('config_search_keywords');
        $this->id = 'footer';
        
        $this->children = array(              
            'module/newsletter',             
        );
        
        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/footer.tpl')) {
            $this->template = $this->config->get('config_template') . '/template/common/footer.tpl';
        } else {
            $this->template = 'default/template/common/footer.tpl';
        }
        
        if ($this->config->get('google_analytics_status')) {
            $this->data['google_analytics'] = html_entity_decode($this->config->get('google_analytics_code'), ENT_QUOTES, 'UTF-8');
        } else {
            $this->data['google_analytics'] = '';
        }

        if ($this->isMobileEnabled()) {
            $this->data['giftcard'] = $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=checkout/giftcard');

            $this->children = array(
                'common/column_left',
            );
        }

        $this->render();
    }
    
    private function getManufacturers(){
        //$manufacturers_data = $this->model_catalog_manufacturer->getManufacturersPath();
        $manufacturers_data = $this->model_catalog_manufacturer->getManufacturers();
        
        $manufacturers = array();
        foreach($manufacturers_data as $manufacturer_item){
            //$path = $manufacturer_item['path'];
            
            $manufacturers[] = array(
                'name'      => $manufacturer_item['name'],
                'image'     => $this->model_tool_image->resize($manufacturer_item['image'], 94, 50),
                //'href'      => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/manufacturer/viewManufacturer&manufacturer_id=' . $manufacturer_item['manufacturer_id'] . '&path=' . $path),
                'href'      => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/manufacturer/viewManufacturer&manufacturer_id=' . $manufacturer_item['manufacturer_id']),
            );    
        }
        
        return $manufacturers;
    }
    
	protected function indexOld() {
		$this->language->load('common/footer');
		
        if(stristr($this->config->get('config_email'), 'havhokeren.dk') !== false){
            $email = $this->config->get('config_email');                
        }
        else{
            $email = 'webshop@havhokeren.dk';
        }
        
        $powered_by = 'Havhøkeren - '; //$this->config->get('config_owner') . ' - ';
        $powered_by .= str_replace("\n", ' - ', $this->config->get('config_address')) . ' - ';
		$powered_by .= 'Tlf. ' . $this->config->get('config_telephone') . ' - ';
		$powered_by .= '<a href="mailto:' . $email . '">' . $email . '</a>';
        $this->data['text_powered_by'] = $powered_by;
        //$this->data['text_powered_by'] = sprintf($this->language->get('text_powered_by'), date('Y', time()));
        
		$this->data['template'] = $this->config->get('config_template');		
		$this->data['link'] = HTTP_SERVER . 'index.php?route=information/forhandlen';
                        
		$this->id = 'footer';

        $this->children = array(
            'module/cart_detailview'
        );
            
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/footer.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/common/footer.tpl';
		} else {
			$this->template = 'default/template/common/footer.tpl';
		}
		
		if ($this->config->get('google_analytics_status')) {
			$this->data['google_analytics'] = html_entity_decode($this->config->get('google_analytics_code'), ENT_QUOTES, 'UTF-8');
		} else {
			$this->data['google_analytics'] = '';
		}
		
		$this->render();
	}
}
?>